fix: handle duplicate repository keys in Dictionary and NSMenu#32
Open
ggfevans wants to merge 4 commits intosteipete:mainfrom
Open
fix: handle duplicate repository keys in Dictionary and NSMenu#32ggfevans wants to merge 4 commits intosteipete:mainfrom
ggfevans wants to merge 4 commits intosteipete:mainfrom
Conversation
Replace `Dictionary(uniqueKeysWithValues:)` with `Dictionary(_:uniquingKeysWith:)` to gracefully handle duplicate `fullName` keys that can occur with pinned repositories. Fixes steipete#31 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When the repos array contains duplicate entries with the same id, the cached NSMenuItem would be returned twice and added to the menu twice. The second addItem fails with "Item to be inserted into menu already is in another menu" because the item is already in the menu. Fix by deduplicating repos by id before iterating. This uses the existing usedRepoKeys set but populates it BEFORE processing items rather than after. Root cause: same as the dictionary crash - duplicate repositories can appear in the pipeline when the same repo is both fetched from the API and present in the pinned list. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
|
heads up @steipete - low hanging fruit |
Keep the most recently fetched repository data when duplicates exist, rather than the first occurrence. Also fix the same crash pattern in the iOS target's mergeHydrated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dictionary(uniqueKeysWithValues:)withDictionary(_:uniquingKeysWith:)to prevent crashes when duplicatefullNamekeys occurAppState+Refresh.swiftthat use this patternProblem
The app crashes in two ways when duplicate repositories appear in the data:
EXC_BREAKPOINT (SIGTRAP)in_assertionFailurefrom_NativeDictionary.mergewhenmergeHydratedencounters repositories with duplicatefullNamevaluesRoot Cause
Duplicate repository keys can occur when:
Solution
Dictionary fix
Use
Dictionary(_:uniquingKeysWith:)which gracefully handles duplicates by keeping the first occurrence:Menu fix
Deduplicate repos by id before iterating to build menu items:
Test plan
swift build)Fixes #31
🤖 Generated with Claude Code